import kshPublicBicycleDataApi from '../../api/kshPublicBicycleData'

export const GgzxcMixins = {
  components: {},
  data() {
    return {
      // 自行车基础信息
      zxcBaseInfoLoading: false,
      zxcBaseInfoData: [
        {label: '自行车总量', value: '-', unit: '辆'},
        {label: '在租数量', value: '-', unit: '辆'},
        {label: '未租在桩数量', value: '-', unit: '辆'},
        {label: '未租不在桩数量', value: '-', unit: '辆'}
      ],
      // 注册交易信息
      zxcZcjyInfoLoading: false,
      zxcZcjyInfoData: [
        {label: '当月注册', value: '-', unit: '人'},
        {label: '当日注册', value: '-', unit: '人'},
        {label: '当月交易', value: '-', unit: '次'},
        {label: '当日交易', value: '-', unit: '次'}
      ],
      // 还车top7
      zxcBikeHireLoading: false,
      zxcBikeHireData: {name: [], value1: [], value2: [], value3: []},
      zxcBikeHireLegend: ['还车量', '可还车辆', '可租车辆'],
      // 租车top7
      zxcBikeRentalLoading: false,
      zxcBikeRentalData: {name: [], value1: [], value2: [], value3: []},
      zxcBikeRentalLegend: ['租车量', '可还车辆', '可租车辆'],
      // 租车时段统计
      zxcRentalTimeLoading: false,
      zxcRentalTimeData: {name: [], value: []},
      // 自行车数据分析
      zxcBikeHireAnalysisLoading: false,
      zxcBikeHireAnalysisData: {name: [], value: []},
      // 站点数据
      zxcStations: [],
      // 租车周期选择
      zxcZcOption: [
        {label: '日', code: 'day'},
        {label: '月', code: 'month'}
      ]
    }
  },
  methods: {
    // 进入页面时执行
    openGgzxcPage() {
      this.handleZxcGetBasicInformation()
      this.handleGetWechatData()
      this.handleGetTopBikeHire()
      this.handleGetTopBikeRental()
      this.handleGetRentalBikeByTime()
      this.handleGetBikeHireAnalysis(1)
    },
    // 获取自行车基础信息
    handleZxcGetBasicInformation() {
      // this.zxcBaseInfoLoading = true
      kshPublicBicycleDataApi.getBasicInformation()
        .then(res => {
          const data = res.data
          this.zxcBaseInfoData = [
            {label: '自行车总量', value: data.total || '0', unit: '辆'},
            {label: '在租数量', value: data.runningCount || '0', unit: '辆'},
            {label: '未租在桩数量', value: data.pointCount || '0', unit: '辆'},
            {label: '未租不在桩数量', value: data.notPointCount || '0', unit: '辆'}
          ]
          // this.zxcBaseInfoLoading = false
        })
        .catch(() => {
          // this.zxcBaseInfoLoading = false
        })
    },
    // 获取注册交易信息数据
    handleGetWechatData() {
      // this.zxcZcjyInfoLoading = true
      kshPublicBicycleDataApi.getWechatData()
        .then(res => {
          const data = res.data
          this.zxcZcjyInfoData = [
            {label: '当月注册', value: data.register_month || '0', unit: '人'},
            {label: '当日注册', value: data.register_day || '0', unit: '人'},
            {label: '当月交易', value: data.trade_month || '0', unit: '次'},
            {label: '当日交易', value: data.trade_day || '0', unit: '次'}
          ]
          // this.zxcZcjyInfoLoading = false
        })
        .catch(() => {
          // this.zxcZcjyInfoLoading = false
        })
    },
    // 获取还车TOP7 情况
    handleGetTopBikeHire() {
      const {startTime, endTime} = this.getCurrentDate('last7')
      // this.zxcBikeHireLoading = true
      kshPublicBicycleDataApi.selectTopBikeHire({startTime: startTime, endTime: endTime})
        .then(res => {
          const data = res.data
          this.zxcBikeHireData = {name: [], value1: [], value2: [], value3: []}
          for (let i = 0; i < data.canHireList.length; i++) {
            this.zxcBikeHireData.name.push(data.canHireList[i].stationName)
            this.zxcBikeHireData.value1.push(data.hireList[i].cou)
            this.zxcBikeHireData.value2.push(data.canHireList[i].canRestore)
            this.zxcBikeHireData.value3.push(data.canHireList[i].canHire)
          }
          // this.zxcBikeHireLoading = false
        })
        .catch(() => {
          // this.zxcBikeHireLoading = false
        })
    },
    // 获取还车TOP7 情况
    handleGetTopBikeRental() {
      const {startTime, endTime} = this.getCurrentDate('last7')
      // this.zxcBikeRentalLoading = true
      kshPublicBicycleDataApi.selectTopBikeRental({startTime: startTime, endTime: endTime})
        .then(res => {
          const data = res.data
          this.zxcBikeRentalData = {name: [], value1: [], value2: [], value3: []}
          for (let i = 0; i < data.canHireList.length; i++) {
            this.zxcBikeRentalData.name.push(data.canHireList[i].stationName)
            this.zxcBikeRentalData.value1.push(data.hireList[i].cou)
            this.zxcBikeRentalData.value2.push(data.canHireList[i].canRestore)
            this.zxcBikeRentalData.value3.push(data.canHireList[i].canHire)
          }
          // this.zxcBikeRentalLoading = false
        })
        .catch(() => {
          // this.zxcBikeRentalLoading = false
        })
    },
    // 获取租车时段统计数据
    handleGetRentalBikeByTime() {
      const {startTime, endTime} = this.getCurrentDate('yesterday')
      // this.zxcRentalTimeLoading = true
      kshPublicBicycleDataApi.selectRentalBikeByTime({startTime: startTime, endTime: endTime})
        .then(res => {
          const data = res.data
          this.zxcRentalTimeData = {name: [], value: []}
          data.forEach(item => {
            this.zxcRentalTimeData.name.push(item.hour)
            this.zxcRentalTimeData.value.push(item.cou)
          })
          // this.zxcRentalTimeLoading = false
        })
        .catch(() => {
          // this.zxcRentalTimeLoading = false
        })
    },
    // 获取自行车日月数据
    handleGetBikeHireAnalysis(type) {
      // this.zxcBikeHireAnalysisLoading = true
      kshPublicBicycleDataApi.selectBikeHireAnalysis(type)
        .then(res => {
          const data = res.data
          this.zxcBikeHireAnalysisData = {name: [], value: []}
          data.forEach(item => {
            this.zxcBikeHireAnalysisData.name.push(item.dateName)
            this.zxcBikeHireAnalysisData.value.push(item.cou)
          })
          // this.zxcBikeHireAnalysisLoading = false
        })
        .catch(() => {
          // this.zxcBikeHireAnalysisLoading = false
        })
    },
    zxcBikeClick(type) {
      let str = ''
      if (type === 1) {
        str = this.zxcBikeHireData.name.join(',')
      } else if (type === 2) {
        str = this.zxcBikeRentalData.name.join(',')
      }
      kshPublicBicycleDataApi.selectStationDetail(str)
        .then(res => {
          this.zxcStations = res.data
          this.$refs.map.clearMarkers()
          this.$refs.map.addCircleMarkers(this.zxcStations, 'zxcStations')
        })
        .catch(() => {

        })
    },
    zxcZcClick(e) {
      if (e.code === 'day') {
        this.handleGetBikeHireAnalysis(1)
      } else if (e.code === 'month') {
        this.handleGetBikeHireAnalysis(2)
      }
    }
  }
}
